﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Cloak.NUnit;
using Cloak.Reflection;
using NUnit.Framework;

namespace Ruleweaver.Rules
{
	public class CreateMemberRuleFromField : Behavior
	{
		private CheckRule _rule;
		private MemberInfo _field;
		private MemberRule _memberRule;

		protected override void Given()
		{
			_rule = Rule.Check(Reflect.Func<ICheckable<int>, Check<int>>(Checkable.IsPositive));

			_field = typeof(TestTarget).GetField("Foo");
		}

		protected override void When()
		{
			_memberRule = Rule.Member(_field, _rule);
		}

		[Then]
		public void MemberIsField()
		{
			Assert.AreEqual(_field, _memberRule.Member);
		}

		[Then]
		public void MemberTypeIsFieldType()
		{
			Assert.AreEqual(typeof(int), _memberRule.MemberType);
		}

		[Then]
		public void RuleIsOriginal()
		{
			Assert.AreEqual(_rule, _memberRule.Rule);
		}

		[Then]
		public void HasFieldType()
		{
			Assert.AreEqual(RuleType.Field, _memberRule.Type);
		}

		private sealed class TestTarget
		{
			public int Foo = 1;
		}
	}
}